<template>

  <elm-page-bb class="elm-edit">
    <div>
    <el-card  shadow="hover" style="margin: 0px 0;">
      <div slot="header">
        <span>项目信息</span>
      </div>
    <el-form ref="model" :model="model" size="small" label-width="120px">
      <elm-row>
        <el-form-item label="项目编号">
          <el-input v-model="model.sys_code_key" disabled placeholder="自动生成无需填写"></el-input>
        </el-form-item>
        <el-form-item label="名称" prop="name" :rules="[{ required: true, message: '名称必须填写'}]">
          <el-input type="name" v-model="model.name" :disabled="disable"></el-input>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="项目类型">
          <elm-select-tree v-model="model.type" url="/business/my/business/GetPjTree" path-url="/business/my/business/GetPjPath" :disabled="disable"></elm-select-tree>
        </el-form-item>
        <el-form-item label="项目资金" prop="money" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
          <el-input v-model="model.money" :disabled="disable">
            <template slot="append"><div style="width: 25px;text-align: center;">万元</div></template>
          </el-input>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="所属部门">
          <elm-org v-model="model.org" :disabled="disable"></elm-org>
        </el-form-item>
        <el-form-item label="项目经理">
          <elm-ei v-model="model.manager" disabled></elm-ei>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="开工日期">
          <el-date-picker v-model="model.b_sdate" value-format="yyyy-MM-dd" type="date" style="width: 100%" :disabled="disable">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="承揽人">
          <elm-ei v-model="model.saler" :disabled="disable"></elm-ei>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="订单编号">
          <elm-order v-model="model.order_key" :disabled="disable"></elm-order>
        </el-form-item>
        <el-form-item label="登记人" prop="manager">
          <elm-ei v-model="model.booker" :disabled="disable"></elm-ei>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="合同编号">
          <elm-contract v-model="model.contract_key" :disabled="disable"></elm-contract>
        </el-form-item>
        <el-form-item></el-form-item>
      </elm-row>
      <el-form-item label="项目概要">
        <el-input type="textarea" v-model="model.description" :rows="2" :disabled="disable"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input type="textarea" v-model="model.remark" :rows="2" :disabled="disable"></el-input>
      </el-form-item>
    </el-form>
    </el-card>
    <el-card  shadow="hover" style="margin: 10px 0;">
      <div slot="header">
        <span>委托信息</span>
      </div>
      <el-form size="small" label-width="120px">
      <elm-row>
        <el-form-item label="委托单位">
          <el-input v-model="model.a_org" :disabled="disable"></el-input>
        </el-form-item>
        <el-form-item label="委托日期">
          <el-date-picker v-model="model.a_date" value-format="yyyy-MM-dd" type="date" style="width: 100%" :disabled="disable">
          </el-date-picker>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="联系人">
          <el-input v-model="model.a_user" :disabled="disable"></el-input>
        </el-form-item>
        <el-form-item label="联系方式">
          <el-input v-model="model.a_user_call" :disabled="disable"></el-input>
        </el-form-item>
      </elm-row>
        <el-form-item label="备注及要求">
          <el-input type="textarea" v-model="model.a_remark" :rows="3" :disabled="disable"></el-input>
        </el-form-item>
      </el-form>
    </el-card>
    </div>
    <template #bottom>
      <el-button type="success" size="small" @click="submit" model. v-if="!disable">立即保存</el-button>
      <el-button size="small" @click="close" v-if="!disable">取消</el-button>
      <el-button size="small" @click="close" v-if="disable">返回</el-button>
    </template>
  </elm-page-bb>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      model: {
        pid: elm.dialog.request.pid,
        progress:0,
        manager:null,
      },
      disable:false
    }
  },
  async created() {
    if(this.model.manager==null||this.model.manager=="")
      this.model.manager=await this.get_user_ei();
  },
  mounted() {
    this.DE_INFO = elm.dialog.request;

    this.disable = this.DE_INFO.disable;
  },
  methods: {
    async submit() {
      await this.$refs["model"].validate();
      var res = await elm.post('/business/my/business/UpsertPj', this.model);
      if (res == true) {
        this.close();
        this.v('保存成功。');
        this.request.callVue.tablebinding();
      }
      else {
        this.error('保存失败，请稍后尝试。');
      }
    },
    async get_user_ei(){
      var res = await elm.post('/system/login/GetUserEi');
      //console.log(res);
      if(res.length>0)
        return res[0].emp_code;
      else
        return "";
    },
  }
}
</script>

<style scoped>
</style>